//
//  WhzDistrictPopoverView.m
//  WhzMT
//
//  Created by whz on 16/12/12.
//  Copyright © 2016年 whz. All rights reserved.
//

#import "WhzDistrictPopoverView.h"

@interface WhzDistrictPopoverView ()

/** 顶部视图*/
@property(nonatomic, strong)UIView *topView;

/** 切换城市按钮*/
@property(nonatomic, strong)UIButton *btnChangeCity;

/** 顶部视图右侧的箭头图片*/
@property(nonatomic, strong)UIImageView *imageViewTopViewRight;

@end

@implementation WhzDistrictPopoverView

- (instancetype)init {

    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - 初始化UI

- (void)setupUI {

    self.frame = CGRectMake(0, 0, 350, 350);
    
    [self loadTopView];
    [self loadTableView];
}

/** 加载tableView视图*/
- (void)loadTableView {

    // 左侧 一级 tableView
    self.tableViewLeft = [[UITableView alloc] initWithFrame:CGRectMake(0, self.topView.bounds.size.height, self.bounds.size.width * 0.5, self.bounds.size.height)];
    [self addSubview:self.tableViewLeft];
    
    // 右侧 二级 tableView
    self.tableViewRight = [[UITableView alloc] initWithFrame:CGRectMake(self.tableViewLeft.bounds.size.width, self.topView.bounds.size.height, self.bounds.size.width * 0.5, self.bounds.size.height)];
    [self addSubview:self.tableViewRight];
    
    
}

/** 加载顶部视图*/
- (void)loadTopView {
    
    // 创建顶部视图 view
    self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(self.frame), 40)];
    self.topView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.topView];
    
    // 创建切换城市按钮 button
    self.btnChangeCity = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(self.topView.frame), CGRectGetMaxY(self.topView.frame))];
    [self.btnChangeCity setTitle:@"切换城市" forState:UIControlStateNormal];
    [self.btnChangeCity.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [self.btnChangeCity setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.btnChangeCity setImage:[UIImage imageNamed:@"btn_changeCity"] forState:UIControlStateNormal];
    [self.btnChangeCity setImage:[UIImage imageNamed:@"btn_changeCity_selected"] forState:UIControlStateHighlighted];
    self.btnChangeCity.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    // 设置按钮内容的内边距
    self.btnChangeCity.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    // 设置按钮title的内边距
    self.btnChangeCity.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self.topView addSubview:self.btnChangeCity];
    
    // 创建顶部视图右侧箭头 image
    self.imageViewTopViewRight = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.btnChangeCity.frame)-20, self.btnChangeCity.bounds.size.height/2-10, 20, 20)];
    self.imageViewTopViewRight.image = [UIImage imageNamed:@"icon_filter_arrow"];
    [self.btnChangeCity addSubview:self.imageViewTopViewRight];
}

@end
